<template>
    <div class="hello">
        <h1>{{ msg }}</h1>
        <button @click="dingRemind()">
            发钉
        </button>
    </div>
</template>
<script>
export default {
    name: 'HelloWorld',
    data() {
        return {
            msg: 'this is ding page',
            agentId: '',
            corpId: 'dingc4cffb655c00d67f35c2f4657eb6378f',
            timeStamp: '',
            nonceStr: '',
            signature: '',
        }
    },
    methods: {
        // 发ding提醒
        $_getGenerateSignature() {
            let _self = this;
            let postData = {
                company_id: _self.corpId,
                url: window.location.href
            };
            let url = 'user/home/v1/login/generateSignature';
            _self.$_post(url, postData).then(function(res) {
            //获取加密数据
                let resData = res.data;
                _self.agentId = resData.agentId;
                _self.timeStamp = resData.timeStamp;
                _self.nonceStr = resData.nonceStr;
                _self.signature = resData.signature;
                //jsapi鉴权并免登
                dd.config({
                    agentId: _self.agentId,
                    corpId: _self.corpId,
                    timeStamp: _self.timeStamp,
                    nonceStr: _self.nonceStr,
                    signature: _self.signature,
                    betaURL: 1,
                    jsApiList: [
                        'biz.ding.create',
                        'biz.contact.complexPicker',
                        'biz.util.uploadImageFromCamera',
                    ]
                });
                dd.error(function(error) {
                    console.log('5311111111111111');
                });
            });
        },
        dingRemind() {
            let _self = this;
            dd.ready(function() {
                let userid = '03495364391146981';
                dd.biz.ding.create({
                    users: [userid], // 用户列表，工号
                    corpId: 'dingc4cffb655c00d67f35c2f4657eb6378f', // 企业id
                    type: 2, // 附件类型 1：image  2：link
                    alertType: 2, // 钉发送方式 0:电话, 1:短信, 2:应用内
                    alertDate: { "format": "yyyy-MM-dd HH:mm", "value": "2015-05-09 08:00" },
                    attachment: {
                        title: 'train.dingMes',
                        url: 'http://www.baidu.com',
                        image: '',
                        text: 'train.dingMes'
                    }, // 附件信息，数据格式参考下文1.0版发钉的附件信息
                    text: '', // 正文
                    bizType: 1, // 业务类型 0：通知DING；1：任务；2：会议；
                    confInfo: {
                        bizSubType: 0, // 子业务类型如会议：0：预约会议；1：预约电话会议；2：预约视频会议；（注：目前只有会议才有子业务类型）
                        location: '某某会议室', //会议地点；（非必填）
                        startTime: { "format": "yyyy-MM-dd HH:mm", "value": "2015-05-09 08:00" }, // 会议开始时间
                        endTime: { "format": "yyyy-MM-dd HH:mm", "value": "2015-05-09 08:00" }, // 会议结束时间
                        remindMinutes: 30,
                        remindType: 2 // 会议提前提醒方式。0:电话, 1:短信, 2:应用内
                    },
                    taskInfo: {
                        ccUsers: ['100', '101'], // 抄送用户列表，工号
                        deadlineTime: { "format": "yyyy-MM-dd HH:mm", "value": "2015-05-09 08:00" }, // 任务截止时间
                        taskRemind: 30 // 任务提醒时间，单位分钟0：不提醒；15：提前15分钟；60：提前1个小时；180：提前3个小时；1440：提前一天；
                    },
                    onSuccess: function() {},
                    onFail: function(err) {
                        console.log(err);
                    },
                }).catch(function(error) {
                    //后台记录错误日志 xiangzi 2019-2-22
                    console.log(error);
                });
            });
            dd.error(function(error) {
                console.log('7922222222222222');
            });
        },
    },
    mounted (){
        this.$_getGenerateSignature();
    }
}

</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
    font-weight: normal;
}

ul {
    list-style-type: none;
    padding: 0;
}

li {
    display: inline-block;
    margin: 0 10px;
}

a {
    color: #42b983;
}

</style>
